﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DataLayer;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace BusinnessLogic
{
    public class TaskDetailHandle
    {
        public List<Tasks> TaskDetail(int taskid)
        {
            DataLayer.dlTaskDetails taskdetails = new  DataLayer.dlTaskDetails();
            DataSet TaskData = taskdetails.TaskDetails(taskid);
            List<Tasks> ListTaskDetails = new List<Tasks>();

            for (int i = 0; i < TaskData.Tables[0].Rows.Count; i++)
            {
                Tasks TDetail = new Tasks();

                TDetail.Titel = TaskData.Tables[0].Rows[i]["Titel"].ToString();
                TDetail.Description = TaskData.Tables[0].Rows[i]["Description"].ToString();
                TDetail.Username = TaskData.Tables[0].Rows[i]["Login"].ToString();
                TDetail.Productname = TaskData.Tables[0].Rows[i]["Name"].ToString();
                TDetail.Sprinttitel = TaskData.Tables[0].Rows[i]["STitel"].ToString();
                TDetail.Userstorytitel = TaskData.Tables[0].Rows[i]["USTitel"].ToString();
                TDetail.Status = TaskData.Tables[0].Rows[i]["Status"].ToString();
                int ewl;
                int.TryParse(TaskData.Tables[0].Rows[i]["EstimatedWorkload"].ToString(), out ewl);
                TDetail.Estimatedworkload = ewl;
                int rwl;
                int.TryParse(TaskData.Tables[0].Rows[i]["RealWorkload"].ToString(), out rwl);
                TDetail.RealWorkload = rwl;
                TDetail.Impedimenttitel = TaskData.Tables[0].Rows[i]["ITitel"].ToString();
                try
                {
                    TDetail.ImpedimentID = int.Parse(TaskData.Tables[0].Rows[i]["ImpedimentID"].ToString());
                }
                catch
                {
                    // no impediment is found....
                }
                TDetail.Comment = TaskData.Tables[0].Rows[i]["Comment"].ToString();
                TDetail.Productid = int.Parse(TaskData.Tables[0].Rows[i]["ProductId"].ToString());

                ListTaskDetails.Add(TDetail);
            }
            return ListTaskDetails;
            
        }
        public void inserttask(int taskid , string comment)
        {
            dlTaskDetails tempsave = new dlTaskDetails();
            tempsave.InsertCommentDB(taskid, comment);
        }

        public void tempsavestatusworkload(int taskid, string status, int rworkload, int eworkload)
        {
            dlTaskDetails tempsave = new dlTaskDetails();
            tempsave.InsertStatusandRealworkloadDB(taskid, status, rworkload);

            dltaskhistory edithistory = new dltaskhistory();
            edithistory.AddTaskhistory(taskid, eworkload, rworkload, status);

        }

    }
}
